local skynet = require "skynet"
local serpent = require "serpent"

local log = {}

--日常打印
function log.info(title, body)
    if __LOG_LEVEL___ > 1 then 
        return
    end
    
    title = serpent.block(title).." "
    local source = debug.getinfo(2).source
    local currentline = debug.getinfo(2).currentline
    if body~=nil then 
        skynet.error("LIGHT_GREEN;"..source..":"..currentline.."; ".."[INFO]  "..title..serpent.block(body))
    else 
        skynet.error("LIGHT_GREEN;"..source..":"..currentline.."; ".."[INFO]  "..title)
    end
end

function log.info2(...)
    if __LOG_LEVEL___ > 1 then 
        return
    end

    title = serpent.block(title).." "
    local source = debug.getinfo(2).source
    local currentline = debug.getinfo(2).currentline
    skynet.error("LIGHT_GREEN;"..source..":"..currentline.."; ", ...)
end

--排查输出
function log.debug(title, body)
    if __LOG_LEVEL___ > 2 then 
        return
    end

    title = serpent.block(title).." "
    local source = debug.getinfo(2).source
    local currentline = debug.getinfo(2).currentline
    if body~=nil then 
        skynet.error("YELLOW;"..source..":"..currentline.."; ".."[DEBUG]  "..title..serpent.block(body))
    else 
        skynet.error("YELLOW;"..source..":"..currentline.."; ".."[DEBUG]  "..title)
    end
end

function log.debug2(...)
    if __LOG_LEVEL___ > 2 then 
        return
    end

    title = serpent.block(title).." "
    local source = debug.getinfo(2).source
    local currentline = debug.getinfo(2).currentline
    skynet.error("YELLOW;"..source..":"..currentline.."; ", ...)
end

--警告输出
function log.warning(title, body)
    if __LOG_LEVEL___ > 3 then 
        return
    end

    title = serpent.block(title).." "
    local source = debug.getinfo(2).source
    local currentline = debug.getinfo(2).currentline
    if body~=nil then 
        skynet.error("PURPLE;"..source..":"..currentline.."; ".."[WARNING]  "..title..serpent.block(body))
    else 
        skynet.error("PURPLE;"..source..":"..currentline.."; ".."[WARNING]  "..title)
    end
end

function log.warning2(...)
    if __LOG_LEVEL___ > 3 then 
        return
    end

    title = serpent.block(title).." "
    local source = debug.getinfo(2).source
    local currentline = debug.getinfo(2).currentline
    skynet.error("PURPLE;"..source..":"..currentline.."; ", ...)
end

--错误输出
function log.error(title, body)
    title = serpent.block(title).." "
    local source = debug.getinfo(2).source
    local currentline = debug.getinfo(2).currentline
    if body~=nil then 
        skynet.error("RED;"..source..":"..currentline.."; ".."[ERR]  "..title..serpent.block(body))
    else 
        skynet.error("RED;"..source..":"..currentline.."; ".."[ERR]"  ..title)
    end
end

function log.error2(...)
    title = serpent.block(title).." "
    local source = debug.getinfo(2).source
    local currentline = debug.getinfo(2).currentline
    skynet.error("RED;"..source..":"..currentline.."; ", ...)
end

return log